import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { defHttp } from '/@/utils/http/axios';


export const columns : BasicColumn[] = [
  {
    title: '分类名称',
    dataIndex: 'categoryName'
  },
  {
    title: '分类编号',
    dataIndex: 'categoryNo'
  },
  // {
  //   title: '父分类编号',
  //   dataIndex: 'parentId'
  // },
  {
    title: '分类排序',
    dataIndex: 'categorySort'
  },
  {
    title: '分类说明',
    dataIndex: 'categoryRemark'
  },
  {
    title: '创建时间',
    dataIndex: 'createTime'
  }
];

export const searchFormSchema : FormSchema[] = [
  {
    label: '分类名称',
    field: 'categoryName',
    component: 'Input'
  },
];
//产品分类
export const formSchema : FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'categoryId', component: 'Input', show: false },
  { label: '', field: 'isEdit', component: 'InputNumber', show: false },
  {
    label: '分类名称',
    field: 'categoryName',
    component: 'Input',
    rules: [{ required: true, message: "请输入分类名称" }],
    colProps: { span: 22 },
    dynamicDisabled: ({ values }) => {
     if (values.isEdit != undefined && values.isEdit == true) {
       return true
     } else {
       return false
     }
    },
  },
  {
    label: '分类编号',
    field: 'categoryNo',
    component: 'InputNumber',
    colProps: { span: 22 },
    rules: [{ required: true, message: "请输入分类编号" }],
    dynamicDisabled: ({ values }) => {
     if (values.isEdit != undefined && values.isEdit == true) {
       return true
     } else {
       return false
     }
    },
  },
  {
    label: '父分类',
    field: 'parentId',
    component: 'ApiTreeSelect',
    colProps: { span: 22 },
    componentProps: {
      api: () => defHttp.get({ url: '/device/productCategory/list' }),
      showSearch: true,// 开启搜索
      placeholder: '请选择父类型',
      treeNodeFilterProp: 'categoryName', // 这里要指定和label或者value字段同一个属性
      fieldNames: {
        label: "categoryName",
        key: "categoryId",
        value: "categoryId",
      },
      getPopupContainer: () => document.body,
    },
    rules: [{ required: false, message: "请选择父类型" }],
    dynamicDisabled: ({ values }) => {
     if (values.isEdit != undefined && values.isEdit == true) {
       return true
     } else {
       return false
     }
    },
  },
  {
    label: '分类排序',
    field: 'categorySort',
    component: 'Input',
    colProps: { span: 22 },
    componentProps: {
      type: 'number',
    },
    dynamicDisabled: ({ values }) => {
      if (values.isEdit != undefined && values.isEdit == true) {
        return true
      } else {
        return false
      }
    },

  },
  {
    label: '分类说明',
    field: 'categoryRemark',
    component: 'Input',
    colProps: { span: 22 },
    dynamicDisabled: ({ values }) => {
     if (values.isEdit != undefined && values.isEdit == true) {
       return true
     } else {
       return false
     }
    },
  }
];
